﻿var Index = 0;

function ClientAddAdvImage() {
    belongSite = document.getElementById("drpSelectSiteForAdvImage").options[document.getElementById("drpSelectSiteForAdvImage").selectedIndex].value;
    Url = Portal.CMS.AdvImage.GetAddNewUrl(belongSite).value;
    if (Url.indexOf("ERROR") != -1) {
        alert(Url);
        return;
    }

    //window.showModalDialog(Url, "", "dialogHeight: 600px; dialogWidth: 800px; dialogTop: 10px; dialogLeft: 150px; edge: Raised; center: Yes; help: No; scroll: Yes; status: Yes;");
    window.open(Url, '_blank');
    //FilterFunc();
}

function SaveClientAddAdvImage() {
    belongSite = document.getElementById("txtBelongSite").value;
    Subject = document.getElementById("txtSubject").value;
    Description = document.getElementById("txtDescription").value;
    retValue = Portal.CMS.AddAdvImage.ServerSideAddAdvImage(belongSite, Subject, Description).value;
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
        return;
    }
    alert(retValue);
    window.close();
}


function ClientDeleteAdvImage(AdvImageId) {

    retValue = Portal.CMS.AdvImage.ServerSideCheckAllowDelete(AdvImageId).value;
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
        return;
    }

    Msg = Portal.CMS.AdvImage.GetConfirmDeleteMsg().value;
    if (confirm(Msg) == false) return;
    RetValue = Portal.CMS.AdvImage.ServerSideDeleteAdvImage(AdvImageId).value;
    if (RetValue.indexOf("ERROR") != -1) {
        alert(RetValue);
        return;
    }
    alert(RetValue);
    FilterFunc();
}

function ShowClientUpdateUrlForm(AdvImageId) {
    Url = Portal.CMS.AdvImage.GetShowUpdateForm(AdvImageId).value;
    if (Url.indexOf("ERROR") != -1) {
        alert(Url);
        return;
    }
    window.open(Url, '_blank');
    //window.showModalDialog(Url, null, 'dialogHeight: 600px; dialogWidth: 800px; dialogTop: 10px; dialogLeft: 150px; edge: Raised; center: Yes; help: No; scroll: Yes; status: Yes;'); 
    //FilterFunc();
}

function ShowFormAppendLink(AdvImageId) {
    Url = Portal.CMS.UpdateAdvImage.GetShowAppendForm(AdvImageId).value;
    if (Url.indexOf("ERROR") != -1) {
        alert(Url);
        return;
    }
    window.showModalDialog(Url, null, 'dialogHeight: 600px; dialogWidth: 800px; dialogTop: 10px; dialogLeft: 150px; edge: Raised; center: Yes; help: No; scroll: Yes; status: Yes;');
    value = Portal.CMS.UpdateAdvImage.GetHtml(AdvImageId).value;
    if (value.indexOf("ERROR") == -1) {
        document.getElementById("divFormContent").innerHTML = value;
    }
}

function ClientSaveUpdateAdvImage(AdvImageId) {
    Subject = document.getElementById("txtAdvImage").value;
    Description = document.getElementById("txtDescription").value;
    language = document.getElementById("divSelectLanguage").options[document.getElementById("divSelectLanguage").selectedIndex].value;

    RetValue = Portal.CMS.UpdateAdvImage.ServerSideUpdateAdvImage(language, AdvImageId, Subject, Description).value;
    if (RetValue.indexOf("ERROR") != -1) {
        alert(RetValue);
        return;
    }
    alert(RetValue);
}

function ClientSaveListItems(AdvImageId, MaxItems) {
    ListItems = Portal.CMS.ListItems.GetListItemsObject(MaxItems).value;
    for (var Index = 0; Index < ListItems.length; Index++) {
        if (document.getElementById("txtItemName_" + Index.toString()) != null) {
            ListItems[Index].AdvImageItemId = document.getElementById("txtItemId_" + Index.toString()).value;
            ListItems[Index].AdvImageItemName = document.getElementById("txtItemName_" + Index.toString()).value;
            ListItems[Index].Url = document.getElementById("txtItemUrl_" + Index.toString()).value;
            ListItems[Index].Target = document.getElementById("txtItemTarget_" + Index.toString()).value;
            ListItems[Index].Description = document.getElementById("txtItemDescription_" + Index.toString()).value;
            ListItems[Index].IndexOrder = document.getElementById("txtItemIndexOrder_" + Index.toString()).value;
        }
    }
    language = document.getElementById("divSelectLanguage").options[document.getElementById("divSelectLanguage").selectedIndex].value;

    RetValue = Portal.CMS.ListItems.ServerSideSaveListItems(language, AdvImageId, ListItems).value;
    if (RetValue.indexOf("ERROR") != -1) {
        alert(RetValue);
        return;
    }
    alert(RetValue);
}

function AppendNewRow() {
    document.getElementById("divContentItems").innerHTML = document.getElementById("divContentItems").innerHTML + Portal.CMS.AddAdvImage.ServerSideNewLinkItem(Index).value;
    Index++;
}

function RemoveItem(Index) {
    document.getElementById("divRowItem_" + Index).innerHTML = "";
    Html = document.getElementById("divContentItems").innerHTML;
    document.getElementById("divContentItems").innerHTML = Portal.CMS.AddAdvImage.ProcessHtml(Html, Index).value;
}


function ShowPermissionFuncForm(AdvImageId) {
    Url = Portal.CMS.AdvImage.GetShowFormSetPermission(AdvImageId).value;
    if (Url.indexOf("ERROR") != -1) {
        alert(Url);
        return;
    }
    //window.showModalDialog(Url, null, 'dialogHeight: 600px; dialogWidth: 800px; dialogTop: 10px; dialogLeft: 150px; edge: Raised; center: Yes; help: No; scroll: Yes; status: Yes;');
    window.open(Url, '_blank');
}

function ShowAddToAlbumForm(AdvImageId) {
    Url = Portal.CMS.AdvImage.GetAddToAlbumForm(AdvImageId).value;
    if (Url.indexOf("ERROR") != -1) {
        alert(Url);
        return;
    }
    //window.showModalDialog(Url, null, 'dialogHeight: 600px; dialogWidth: 800px; dialogTop: 10px; dialogLeft: 150px; edge: Raised; center: Yes; help: No; scroll: Yes; status: Yes;'); 
    window.open(Url, '_blank');
}


function ClientAdd2Album(AdvImageId) {
    AlbumId = document.getElementById("drpSelectAlbum").options[document.getElementById("drpSelectAlbum").selectedIndex].value;
    retValue = Portal.CMS.AddToAlbum.ServerSideAddToAlbum(AdvImageId, AlbumId).value;
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
        return;
    }
    alert(retValue);
    window.close();
}

function DetectAdvImageDescription(AdvImageId) {
    language = document.getElementById("divSelectLanguage").options[document.getElementById("divSelectLanguage").selectedIndex].value;

    retValue = Portal.CMS.UpdateAdvImage.ServerGetDescription(language, AdvImageId).value;
    document.getElementById("txtDescription").value = retValue;
}

function DeleteAdvImageItem(AdvImageId, AdvImageItemId) {
    RetValue = Portal.CMS.ListItems.ServerSideCheckDeleteAdvImageItem(AdvImageItemId).value;
    if (RetValue.indexOf("ERROR") != -1) {
        alert(RetValue);
        return;
    }
    Msg = Portal.CMS.ListItems.GetConfirmDeleteMsg().value;
    if (confirm(Msg) == false) return;
    RetValue = Portal.CMS.ListItems.ServerSideDeleteAdvImageItem(AdvImageItemId).value;
    if (RetValue.indexOf("ERROR") != -1) {
        alert(RetValue);
        return;
    }
    alert(RetValue);
    value = Portal.CMS.ListItems.GetHtml(AdvImageId).value;
    if (value.indexOf("ERROR") == -1) {
        document.getElementById("divFormContent").innerHTML = value;
    }
}


function SaveAdvImageItem(Index, AdvImageItemId) {
    Alias = document.getElementById("txtAlias_" + Index.toString()).value;
    AdvImageItemName = document.getElementById("txtItemName_" + Index.toString()).value;
    Url = document.getElementById("txtItemUrl_" + Index.toString()).value;
    Target = document.getElementById("txtItemTarget_" + Index.toString()).value;
    Description = document.getElementById("txtItemDescription_" + Index.toString()).value;
    IndexOrder = document.getElementById("txtItemIndexOrder_" + Index.toString()).value;

    RetValue = Portal.CMS.ListItems.ServerSideSaveAdvImageItem(AdvImageItemId, Alias, AdvImageItemName, Url, Target, Description, IndexOrder).value;
    if (RetValue.indexOf("ERROR") != -1) {
        alert(RetValue);
        return;
    }
    alert(RetValue);
}


function UploadNewImage(AdvImageId) {
    Url = Portal.CMS.ListItems.GetAddAdvImageItemUrl(AdvImageId).value;
    if (Url.indexOf("ERROR") != -1) {
        alert(Url);
        return;
    }
    //window.showModalDialog(Url, null, 'dialogHeight: 600px; dialogWidth: 800px; dialogTop: 10px; dialogLeft: 150px; edge: Raised; center: Yes; help: No; scroll: Yes; status: Yes;');
    window.open(Url, '_blank');
    //    value=Portal.CMS.ListItems.GetHtml(AdvImageId).value;
    //    if(value.indexOf("ERROR")==-1)
    //    {
    //        document.getElementById("divFormContent").innerHTML=value;
    //    }
}


function FilterFunc() {
    document.getElementById("divProcessing").innerHTML = Portal.CMS.AdvImage.GetProcessingText().value;
    setTimeout("RealFilterFunc()", 10);



}


function RealFilterFunc() {
    belongSite = document.getElementById("drpSelectSiteForAdvImage").options[document.getElementById("drpSelectSiteForAdvImage").selectedIndex].value;
    retValue = Portal.CMS.AdvImage.GetHtml(belongSite).value;
    if (retValue.indexOf("ERROR") != -1) {
        document.getElementById("divProcessing").innerHTML = "";
        alert(retValue);
        return;
    }
    document.getElementById("divProcessing").innerHTML = "";
    document.getElementById("divAdvImageMain").innerHTML = retValue;
}


function ShowItems(AdvImageId) {
    Url = Portal.CMS.AdvImage.GetItemsUrl(AdvImageId).value;
    if (Url.indexOf("ERROR") != -1) {
        alert(Url);
        return;
    }
    window.open(Url, "_blank");
}




function ClientJumpAdvImageItem(TabModuleId, MaxItems, ItemPerPage, VisiblePage, CurrentPageIndex, Javascript) {
    document.getElementById("divProcessingAdvImageItem").innerHTML = Portal.CMS.ListItems.GetProcessingText().value;
    setTimeout("RealClientJumpAdvImageItem('" + TabModuleId + "'," + MaxItems + "," + ItemPerPage + "," + VisiblePage + "," + CurrentPageIndex + ",'" + Javascript + "')", 10);
}

function RealClientJumpAdvImageItem(TabModuleId, MaxItems, ItemPerPage, VisiblePage, CurrentPageIndex, Javascript) {
    language = document.getElementById("divSelectLanguage").options[document.getElementById("divSelectLanguage").selectedIndex].value;
    AdvImageId = document.getElementById("txtAdvImageId").value;
    Keyword = document.getElementById("txtKeyword").value;
    RetValue = Portal.CMS.ListItems.GetHtml(language, AdvImageId, Keyword, CurrentPageIndex).value;
    document.getElementById("divProcessingAdvImageItem").innerHTML = "";
    document.getElementById("divFormContent").innerHTML = RetValue;
}




function ClientReading(AdvImageId) {
    document.getElementById("divProcessingAdvImageItem").innerHTML = Portal.CMS.ListItems.GetProcessingText().value;
    setTimeout("RealClientReading('" + AdvImageId + "')", 10);
}


function RealClientReading(AdvImageId) {
    keyword = document.getElementById("txtKeyword").value;
    language = document.getElementById("divSelectLanguage").options[document.getElementById("divSelectLanguage").selectedIndex].value;

    value = Portal.CMS.ListItems.GetHtml(language, AdvImageId, keyword, 0).value;
    if (value.indexOf("ERROR") == -1) {
        document.getElementById("divProcessingAdvImageItem").innerHTML = "";
        document.getElementById("divFormContent").innerHTML = value;
    }
    document.getElementById("divProcessingAdvImageItem").innerHTML = "";
}



function ClientPublishing(AdvImageItemId) {
    retValue = Portal.CMS.ListItems.ServerSideCheckPublishing(AdvImageItemId).value;
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
        return;
    }
    ConfirMsg = Portal.CMS.ListItems.GetConfirmPublishingMsg().value;
    if (confirm(ConfirMsg) == false) return;
    retValue = Portal.CMS.ListItems.ServerSidePublishing(AdvImageItemId).value;
    alert(retValue);
    if (retValue.indexOf("ERROR") != -1) {
        retValue = Portal.CMS.ListItems.GetUnPublishingCaption().value;
        document.getElementById("txtPublishing_" + AdvImageItemId).value = retValue;
    }
}


function ClientUnPublishing(AdvImageItemId) {
    retValue = Portal.CMS.ListItems.ServerSideCheckUnPublishing(AdvImageItemId).value;
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
        return;
    }
    ConfirMsg = Portal.CMS.ListItems.GetConfirmUnPublishingMsg().value;
    if (confirm(ConfirMsg) == false) return;
    retValue = Portal.CMS.ListItems.ServerSideUnPublishing(AdvImageItemId).value;
    alert(retValue);
    if (retValue.indexOf("ERROR") != -1) {
        retValue = Portal.CMS.ListItems.GetPublishingCaption().value;
        document.getElementById("txtPublishing_" + AdvImageItemId).value = retValue;
    }
}

function SyncWithServer(AdvImageId) {
    ConfirmMsg = Portal.CMS.ListItems.GetConfirmSyncMsg().value;
    if (confirm(ConfirmMsg) == false) return;
    document.getElementById("divProcessing").innerHTML = Portal.CMS.ListItems.GetProcessingText().value;
    setTimeout("RealSyncWithServer('" + AdvImageId + "')", 10);
}

function RealSyncWithServer(AdvImageId) {
    retValue = Portal.CMS.ListItems.ServerSideSyncWithServer(AdvImageId).value;
    document.getElementById("divProcessing").innerHTML = "";
    alert(retValue);
}


function UpdateNewAdvImageItem(AdvImageId, AdvImageItemId) {
    Url = Portal.CMS.ListItems.GetUpdatePictureItemsUrl(AdvImageItemId).value;
    if (Url.indexOf("ERROR") != -1) {
        alert(Url);
        return;
    }
    //window.showModalDialog(Url, null, 'dialogHeight: 600px; dialogWidth: 800px; dialogTop: 10px; dialogLeft: 150px; edge: Raised; center: Yes; help: No; scroll: Yes; status: Yes;');
    window.open(Url, '_blank');
}

function PermissionAdvImageItem(AdvImageItemId) {
    Url = Portal.CMS.ListItems.GetPermissionUrlItem(AdvImageItemId).value;
    if (Url.indexOf("ERROR") != -1) {
        alert(Url);
        return;
    }
    //window.showModalDialog(Url, null, 'dialogHeight: 600px; dialogWidth: 800px; dialogTop: 10px; dialogLeft: 150px; edge: Raised; center: Yes; help: No; scroll: Yes; status: Yes;');
    window.open(Url, '_blank');
}


function ClientSaveAdvImageItemHtml(AdvImageItemId) {
    var instanceName = "ctl04";
    var oEditor = FCKeditorAPI.GetInstance(instanceName);
    bodyText = oEditor.GetXHTML(true);
    rValue = Portal.CMS.AdvImageHtml.ServerSideHtml(AdvImageItemId, bodyText).value;
    alert(rValue);
}

function ClientHtmlItem(AdvImageId, AdvImageItemId) {
    Url = Portal.CMS.ListItems.GetUpdateHtmlUrl(AdvImageId, AdvImageItemId).value;
    if (Url.indexOf("ERROR") != -1) {
        alert(Url);
        return;
    }
    //window.showModalDialog(Url, null, 'dialogHeight: 600px; dialogWidth: 800px; dialogTop: 10px; dialogLeft: 150px; edge: Raised; center: Yes; help: No; scroll: Yes; status: Yes;');
    window.open(Url, '_blank');
}

function ClientSyncItem(AdvImageId, AdvImageItemId) {
    if (confirm(Portal.CMS.ListItems.GetConfirmSyncAllMsg().value) == false) {
        return;
    }
    document.getElementById("divProcessing").innerHTML = Portal.CMS.ListItems.GetProcessingText().value;
    setTimeout("RealClientSyncItem('" + AdvImageId + "','" + AdvImageItemId + "')", 10);
}

function RealClientSyncItem(AdvImageId, AdvImageItemId) {
    rValue = Portal.CMS.ListItems.ServerSideSyncAdvImageItem(AdvImageId, AdvImageItemId).value;
    document.getElementById("divProcessing").innerHTML = "";
    alert(rValue);
}


function ClientSyncAdvImage(AdvImageId) {
    if (confirm(Portal.CMS.AdvImage.GetConfirmSyncAllMsg().value) == false) {
        return;
    }
    document.getElementById("divProcessing").innerHTML = Portal.CMS.AdvImage.GetProcessingText().value;
    setTimeout("RealClientSyncAdvImage('" + AdvImageId + "')", 10);
}

function RealClientSyncAdvImage(AdvImageId) {
    rValue = Portal.CMS.AdvImage.ServerSideSyncAdvImage(AdvImageId).value;
    document.getElementById("divProcessing").innerHTML = "";
    alert(rValue);
}

function ClientUploadAvatar(AdvImageId, AdvImageItemId) {
    Url = Portal.CMS.ListItems.GetUploadAvatarUrl(AdvImageId, AdvImageItemId).value;
    window.open(Url, '_blank');
}